﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Gagnatek.WebSite.Models;

namespace Gagnatek.WebSite.Controllers
{
    public class HomeController : Controller
    {
        private GagnatekDBEntities db = new GagnatekDBEntities();

        public ActionResult Index()
        {
            if (User.IsInRole("Owner"))
                return View("AdminIndex");
            else if (User.IsInRole("Customer"))
                return View("CustomerIndex", db.Users.Where(u => u.email.Equals(User.Identity.Name)).FirstOrDefault());

            return View(db.Medias.ToList());
        }

        public ActionResult Search()
        {
            var query = Request["search"];

            var q = from m in db.Medias
                    where m.name.Contains(query) ||
                     m.description.Contains(query) ||
                     m.Authors.name.Contains(query)
                    select m;

            return View("Index", q.ToList());

        }

        public ActionResult About()
        {
            return View();
        }
    }
}
